package org.study.mybatis.dynamic.boot.service;

import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.study.mybatis.dynamic.boot.mapper.Ds1UserMapper;
import org.study.mybatis.dynamic.boot.mapper.Ds2UserMapper;

/**
 * 类的描述
 *
 * @author Administrator
 * @date 2022-07-12
 */
@Service
public class TestServiceImpl implements TestService {
    @Autowired
    private Ds1UserMapper ds1UserMapper;
    @Autowired
    private Ds2UserMapper ds2UserMapper;

    @DSTransactional
    @Override
    public void truncateTable() {
        ds1UserMapper.truncateTable();
        ds2UserMapper.truncateTable();
    }

    @DSTransactional
    @Override
    public void testCommit() {
        ds1UserMapper.insert("AAA", 20);
        ds2UserMapper.insert("BBB", 20);
    }

    @DSTransactional
    @Override
    public void testRollback01(boolean ex) {
        ds1UserMapper.insert("AAA", 20);
        if (ex) {
            int result = 100 / 0;
        }
        ds2UserMapper.insert("BBB", 20);
    }

    @DSTransactional
    @Override
    public void testRollback02(boolean ex) {
        ds1UserMapper.insert("AAA", 20);
        ds2UserMapper.insert("BBB", 20);
        if (ex) {
            int result = 100 / 0;
        }
    }
}
